package com.example.administrator.androidlibrary.activity;

import android.app.Activity;
import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.transition.Explode;
import android.transition.Fade;
import android.transition.Slide;
import android.transition.Transition;
import android.transition.TransitionInflater;
import android.view.Gravity;
import android.view.animation.LinearInterpolator;

import com.example.administrator.androidlibrary.R;
import com.example.administrator.androidlibrary.base.BaseActivity;
import com.example.administrator.androidlibrary.utils.ActivityAnimateUtil;

import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Administrator on 2018/4/4 0004.
 */

public class SplashActivity extends BaseActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        initTimer();
    }

    private void initTimer() {
        Observable.create(new ObservableOnSubscribe<Integer>() {
            @Override
            public void subscribe(ObservableEmitter<Integer> e) throws Exception {
                try {
                    Thread.sleep(2000);
                    e.onNext(1);
                    Thread.sleep(1000);
                    e.onNext(2);
                    e.onComplete();
                }catch (Exception e2){}
            }
        }).subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<Integer>() {
                    @Override
                    public void accept(Integer integer) throws Exception {
                        switch (integer){
                            case 1:
                                startActivity(new Intent(SplashActivity.this,MainActivity.class), ActivityOptions.makeSceneTransitionAnimation(SplashActivity.this).toBundle());
                                break;
                            case 2:
                                finish();
                                break;
                        }
                    }
                });
    }

    @Override
    public void initActivityAnimation() {
        setActivityAnimate(ActivityAnimateUtil.getFadeAnimate(),ActivityAnimateUtil.getFadeAnimate());
    }
}
